// utils/device.js
export function isIPhone7Plus() {
    try {
        const info = uni.getSystemInfoSync();
        const model = info.model.toLowerCase();
        const pixelRatio = info.pixelRatio;
        const screenWidth = info.screenWidth;
        const screenHeight = info.screenHeight;
        const isIPhone = model.indexOf('iphone') !== -1;
        const is7PlusModel = model.indexOf('iphone 7 plus') !== -1 || model.indexOf('iphone7,2') !== -1;
        const isPixelRatio3 = pixelRatio === 3;
        let is7PlusScreen = false;
        const isLandscape = screenWidth > screenHeight;

        if (isLandscape) {
            is7PlusScreen = Math.max(screenWidth, screenHeight) === 736;
        } else {
            is7PlusScreen = Math.min(screenWidth, screenHeight) === 414;
        }

        return isIPhone && (is7PlusModel || (isPixelRatio3 && is7PlusScreen));
    } catch (e) {
        return false;
    }
}

export function isHarmonyOS() {
    try {
        const info = uni.getSystemInfoSync();
        const system = info.system.toLowerCase();
        const model = info.model.toLowerCase();
        
        return system.includes('harmonyos') || 
               system.includes('鸿蒙') ||
               model.includes('harmonyos') ||
               model.includes('鸿蒙');
    } catch (e) {
        return false;
    }
}

// 检测是否为任意 Pro Max 型号
export function isProMaxDevice() {
    try {
        const info = uni.getSystemInfoSync();
        const model = info.model.toLowerCase();
        const pixelRatio = info.pixelRatio;
        const screenWidth = info.screenWidth;
        const screenHeight = info.screenHeight;
        const isIPhone = model.indexOf('iphone') !== -1;
        
        if (!isIPhone) return false;
        
        // 检查是否包含 Pro Max 关键字
        if (model.includes('pro max')) return true;
        
        // 检查特定型号标识符
        const proMaxModels = [
            'iphone12,5',  // 11 Pro Max
            'iphone13,4',  // 12 Pro Max
            'iphone14,3',  // 13 Pro Max
            'iphone14,4',  // 13 Pro Max
            'iphone15,3',  // 14 Pro Max
            'iphone15,4',  // 14 Pro Max
            'iphone16,2',  // 15 Pro Max
        ];
        
        if (proMaxModels.some(id => model.includes(id))) return true;
        
        // 通过屏幕尺寸和像素比进一步判断
        const isLandscape = screenWidth > screenHeight;
        const logicalWidth = isLandscape ? Math.max(screenWidth, screenHeight) : Math.min(screenWidth, screenHeight);
        const logicalHeight = isLandscape ? Math.min(screenWidth, screenHeight) : Math.max(screenWidth, screenHeight);
        
        // Pro Max 系列典型分辨率
        const proMaxResolutions = [
            { width: 414, height: 896 }, // 11 Pro Max
            { width: 428, height: 926 }, // 12/13/14 Pro Max
            { width: 430, height: 932 }, // 15 Pro Max
        ];
        
        const matchesResolution = proMaxResolutions.some(res => 
            (logicalWidth === res.width && logicalHeight === res.height) || 
            (logicalWidth === res.height && logicalHeight === res.width)
        );
        
        return pixelRatio === 3 && matchesResolution;
    } catch (e) {
        return false;
    }
}

// 检测是否为特定型号的 Pro Max
export function isSpecificProMax(modelName) {
    try {
        const info = uni.getSystemInfoSync();
        const model = info.model.toLowerCase();
        return model.includes(modelName.toLowerCase());
    } catch (e) {
        return false;
    }
}

// 仅保留设备检测，移除所有样式应用逻辑
export function applySpecialStyles() {
    // 此函数现在仅作为设备检测的入口，不执行任何样式操作
    // 你可以根据返回值在其他地方应用样式
}